<?php

namespace App\Http\Controllers\Shop;

use App\Models\BalanceLog;
use Illuminate\Http\Request;
use App\Http\Resources\Shop\ShopBalanceLog as ShopBalanceLogResource;
use App\Http\Resources\Shop\ShopBalanceLogCollection;
use App\Http\Controllers\ApiController;
use App\Models\ShopBalanceLog;

class ShopBalanceLogController extends ApiController
{
    /**
     * 财务明细.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $limit = $request->input('size');
        $date = $request->input('date');
        $invoice = $request->input('invoice');

        $orm = ShopBalanceLog::OwnerShop()->orderBy('created_at', 'DESC');

        $invoice && $orm->where('invoice', $invoice);

        if($date) {
            if($date[0] && time($date[0])) {
                $orm->where('created_at', '>', $date[0]);
            }

            if($date[1] && time($date[1])) {
                $orm->where('created_at', '<', $date[1]);
            }
        }

        return new ShopBalanceLogCollection($orm->paginate($limit));
    }
}
